package me.shurufa.activities;

import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.text.TextUtils;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.google.gson.Gson;

import java.util.HashMap;
import java.util.Map;

import butterknife.Bind;
import me.shurufa.R;
import me.shurufa.fragments.CatalogNoDigestNumFragment;
import me.shurufa.model.BookInfo;
import me.shurufa.model.BookInfoResponse;
import me.shurufa.net.NetworkConstants;
import me.shurufa.net.RequestServerTask;
import me.shurufa.utils.Constants;
import me.shurufa.utils.HttpUtil;
import me.shurufa.utils.LogUtils;
import me.shurufa.utils.Utils;

/**
 * 图书->查看这本书的目录跳转的页面
 *
 * @FileName: me.shurufa.activities.CatalogWithBookActivity.java
 * @author: kHRYSTAL
 * @email: 723526676@qq.com
 * @date: 2016-02-02 16:08
 */
public class CatalogWithBookActivity extends BaseActivity implements View.OnClickListener {

    @Bind(R.id.left_text)
    TextView leftText;
    @Bind(R.id.right_image)
    ImageView rightImage;
    @Bind(R.id.right_text)
    TextView rightText;
    @Bind(R.id.toolbar_divider)
    View toolbarDivider;
    @Bind(R.id.fragment_container)
    FrameLayout fragmentContainer;


    private long bookId;
    private BookInfo bookInfo;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        activity_layout_res = R.layout.activity_catalog_with_book;
        super.onCreate(savedInstanceState);
        bookId = getIntent().getLongExtra(Constants.ARG_BOOK_ID,0L);
        try {
            bookInfo = new Gson().fromJson(getIntent().getStringExtra(Constants.ARG_BOOK_INFO),BookInfo.class);
        }catch (Exception e){
            LogUtils.kLog().e("bookinfo parse error");
            bookInfo = null;
        }

        if (bookId == 0L)
            return;
        uiInit();
        initData();
    }

    private void initData() {
        CatalogNoDigestNumFragment fragment = CatalogNoDigestNumFragment.newInstance(bookId);
        fragment.bookInfo = bookInfo;
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.add(R.id.fragment_container,fragment);
        transaction.commit();
    }

    private void uiInit() {
    }

    @Override
    public void onClick(View v) {

    }
}
